-- 游戏中的组件基类

-- 模块定义
local M = 
{
    _base_class = require "objects.Object",
    _class_name = "components.baseComponent";

};
setmetatable (M, {__index = _G;});
_ENV = M;

-- 引用模块
local Tools = require "tools.CommonTools";

-- 方法定义
operation_table = Tools.CreateOperationTable (_base_class);

-- 被添加到entity上时的回调
function operation_table.OnAddedToHost (self, host)
    self._hostEntity = host;
end;

-- 从entity中删除时的回调
function operation_table.OnRemovedFromHost (self, host)
    self._hostEntity = nil;
end;

-- 更新
function operation_table.Update (self, currentTime, deltaTime)
    -- 子类覆盖该方法添加更新逻辑
end;

-- 构造函数，所有组件实例都是在game_entity中添加组件时反射生成的，不要直接new_xxx。
function NewBaseComponent ()
    local instance = _base_class.NewObject ();
    Tools.PrepareInstance (M, instance);

    -- 私有成员
    instance._hostEntity = nil;

    return instance;
end;

return M;
